home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / VideoToolboxSources / Identify.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-13  |  5.8 KB  |  186 lines  |  [TEXT/KAHL]

  1. /* Identify.c
  2. Each routine returns an informative C string. Here are samples. (I suggest you
  3. use BreakLines() to printf the longer ones.)
  4.  
  5. IdentifyCompiler:
  6. "THINK C 5 compiled to generate 68020 instructions,
  7. generate 68881 instructions, and use 12-byte universal-format doubles."
  8.  
  9. IdentifyMachine:
  10. "Denis Pelli’s PowerBook 170 with 68030 and 68882 running System 7.10, ROM 1024K
  11. version 124+6*256. Caching data & instructions."
  12.  
  13. IdentifyModel:
  14. "PowerBook 170"
  15.  
  16. IdentifyVideo(device):
  17. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM) in slot 0"
  18.  
  19. The computer model appears only if the slot==0, which indicates built-in video. The
  20. curly quotes embrace the card name, and the parentheses embrace the driver name.
  21. The driver's version number appears only if it's non-zero.
  22.  
  23. HISTORY:
  24. 1/29/92    dgp wrote IdentifyCompiler.
  25. 2/25/92    dgp    wrote IdentifyMachine.
  26. 8/26/92    dgp get owner and model name from the System file
  27. 2/20/93    dgp    added ROM version
  28. 2/27/93    dgp merged IdentifyCompiler.c and IdentifyMachine.c into the new Identify.c,
  29.             and added IdentifyVideo.
  30. */
  31. #include "VideoToolbox.h"
  32. #include <Traps.h>    // _HWPriv
  33. #include "mc68881.h"
  34.  
  35. /*
  36. This table was complete in summer '92, but does not include the newer models.
  37. However, the table's used only as a backup, when the System lacks a machine name
  38. string, which is a feature of System 7. Since all new machines nominally require
  39. System 7, it is unlikely that it will ever be necessary to look them up in
  40. this table.
  41. */
  42. char machineName[][32]={
  43.     "Unknown Macintosh","Macintosh","Mac XL","Mac 512KE","Mac Plus","Mac SE","Mac II"
  44.     ,"Mac IIx","Mac IIcx","Mac SE/30","Mac Portable","Mac IIci","Unknown Macintosh"
  45.     ,"Mac IIfx","Unknown Macintosh","Unknown Macintosh","Unknown Macintosh"
  46.     ,"Mac Classic","Mac IIsi","Mac LC","Mac Quadra 900","PowerBook 170"
  47.     ,"Mac Quadra 700","Mac Classic II","PowerBook 100","PowerBook 140","Quadra 950"
  48.     ,"Unknown Macintosh"
  49. };
  50.  
  51. char processorName[][32]={
  52.     "unknown processor","68000","68010","68020","68030","68040","unknown processor"
  53. };
  54.  
  55. char fpuName[][40]={
  56.     "no floating point unit","68881","68882","68040 built-in floating point unit"
  57.     ,"unknown floating point unit"
  58. };
  59.  
  60. char *IdentifyCompiler(void)
  61. {
  62.     static char string[200];
  63.     char *compiler,*longs,*floating,version[4],*format;
  64.     double v;
  65.     
  66.     string[0]=0;
  67.     compiler="";
  68.     #if THINK_C
  69.         compiler="THINK ";
  70.     #endif
  71.     #if applec
  72.         compiler="MPW ";
  73.     #endif
  74.     v=0;
  75.     #if THINK_C==1
  76.         v=4;
  77.     #endif
  78.     #if THINK_C>1
  79.         v=THINK_C;
  80.     #endif
  81.     if(v>0.0)sprintf(version,"%1.0f ",v);
  82.     else sprintf(version,"");
  83.     if(mc68020)longs="generate 68020 instructions";
  84.     else longs="not generate 68020 instructions";
  85.     if(mc68881)floating="generate 68881 instructions";
  86.     else floating="do all float arithmetic through SANE";
  87.     if(sizeof(double)==12){
  88.         format="native-format doubles";
  89.         #if THINK_C>1 
  90.             #if !__option(native_fp)
  91.                 format="universal-format doubles";
  92.             #endif
  93.         #endif
  94.     }else format="doubles";
  95.     sprintf(string,"%sC %scompiled to %s, \n%s, and use %ld-byte %s."
  96.         ,compiler,version,longs,floating,sizeof(double),format);
  97.     return string;
  98. }
  99.  
  100. char *IdentifyModel(void)
  101. {
  102.     OSErr error;
  103.     long machine;
  104.     int machines=sizeof(machineName)/sizeof(machineName[0]);
  105.     static char string[32];
  106.  
  107.     string[0]=0;
  108.     error=Gestalt(gestaltMachineType,&machine);
  109.     if(!error){
  110.         GetIndString((unsigned char *)string,kMachineNameStrID,machine);
  111.         p2cstr((unsigned char *)string);
  112.         if(strlen(string)==0){
  113.             if(machine<0 || machine>=machines)machine=0;
  114.             sprintf(string,"%#s",machineName[machine]);
  115.         }
  116.     }
  117.     return string;
  118. }
  119.  
  120. char *IdentifyVideo(GDHandle device)
  121. // E.g. "PowerBook 170 “Macintosh D Built-In Video” (.Display_Video_Apple_TIM)"
  122. {
  123.     static char string[256];
  124.     long quickDraw;
  125.  
  126.     string[0]=0;
  127.     Gestalt(gestaltQuickdrawVersion,&quickDraw);
  128.     if(quickDraw<gestalt8BitQD){
  129.         sprintf(string,"%s ",IdentifyModel());
  130.         sprintf(string,"%s“%s”",string,"1-bit QuickDraw");
  131.     }else{
  132.         if(GetDeviceSlot(device)==0)sprintf(string,"%s ",IdentifyModel());
  133.         sprintf(string,"%s“%s”",string,GDCardName(device));
  134.         if(GDVersion(device)==0)sprintf(string,"%s (%#s)",string,GDName(device));
  135.         else sprintf(string,"%s (%#s version %d)"
  136.             ,string,GDName(device),GDVersion(device));
  137.         sprintf(string,"%s slot %d",string,GetDeviceSlot(device));
  138.     }
  139.     return string;
  140. }
  141.  
  142. char *IdentifyMachine(void)
  143. {
  144.     OSErr error;
  145.     long fpu,processor,system;
  146.     int processors=sizeof(processorName)/sizeof(processorName[0]);
  147.     int fpus=sizeof(fpuName)/sizeof(fpuName[0]);
  148.     static char string[256];
  149.     unsigned char **owner;
  150.     Boolean cacheData=1,cacheInstructions=1;
  151.     long romSize,romVersion;
  152.     
  153.     string[0]=0;
  154.     owner=GetString(-16096);    // Get owner's name from System file
  155.     error=Gestalt(gestaltSystemVersion,&system);
  156.     if(error)return string;                        /* Gestalt not available */
  157.     Gestalt(gestaltProcessorType,&processor);
  158.     if(processor<0 || processor>=processors)processor=processors-1;
  159.     Gestalt(gestaltFPUType,&fpu);
  160.     if(fpu<0 || fpu>=fpus)fpu=fpus-1;
  161.     if(owner!=NULL && *owner[0]>0)sprintf(string,"%#s’s ",*owner);
  162.     sprintf(string,"%s%s",string,IdentifyModel());
  163.     sprintf(string,"%s with %s and %s running System %lx.%lx"
  164.         ,string,processorName[processor],fpuName[fpu]
  165.         ,system/0x100,system%0x100/0x10);
  166.     system%=0x10;
  167.     if(system)sprintf(string,"%s.%lx",string,system);
  168.     Gestalt(gestaltROMSize,&romSize);
  169.     Gestalt(gestaltROMVersion,&romVersion);
  170.     sprintf(string,"%s, %ldK ROM version %ld+%ld*256."
  171.         ,string,romSize/1024,romVersion%256,romVersion/256);
  172.     if(TrapAvailable(_HWPriv)){
  173.         cacheData=SwapDataCache(1);
  174.         SwapDataCache(cacheData);
  175.         cacheInstructions=SwapInstructionCache(1);
  176.         SwapInstructionCache(cacheInstructions);
  177.         if(cacheData || cacheInstructions)sprintf(string,"%s Caching",string);
  178.         else sprintf(string,"%s No caching",string);
  179.         if(cacheData)sprintf(string,"%s data",string);
  180.         if(cacheData && cacheInstructions)sprintf(string,"%s &",string);
  181.         if(cacheInstructions)sprintf(string,"%s instructions",string);
  182.         sprintf(string,"%s.",string);
  183.     }
  184.     return string;
  185. }
  186.